import request from '@/utils/request'
import Qs from 'qs'

const api = {
  user: '/user',
  role: '/role',
  service: '/service',
  permission: '/permission',
  permissionNoPager: '/permission/no-pager',
  orgTree: '/org/tree'
}

export default api

export function getUserList (parameter) {
  return request({
    url: api.user,
    method: 'get',
    params: parameter
  })
}

export function getRoleList (parameter) {
  return request({
    url: api.role,
    method: 'get',
    params: parameter
  })
}

export function getServiceList (parameter) {
  return request({
    url: api.service,
    method: 'get',
    params: parameter
  })
}

export function getPermissions (parameter) {
  return request({
    url: api.permissionNoPager,
    method: 'get',
    params: parameter
  })
}

export function getOrgTree (parameter) {
  return request({
    url: api.orgTree,
    method: 'get',
    params: parameter
  })
}

// id == 0 add     post
// id != 0 update  put
export function saveService (parameter) {
  return request({
    url: api.service,
    method: parameter.id === 0 ? 'post' : 'put',
    data: parameter
  })
}

export function saveSub (sub) {
  return request({
    url: '/sub',
    method: sub.id === 0 ? 'post' : 'put',
    data: sub
  })
}

export function getThirdCompany (parameter) {
  return request({
    url: '/web/ThirdCompany/get_ThirdCompany',
    method: 'get',
    params: parameter
  })
}

export function getAddress (parameter) {
  return request({
    url: '/admin/address/get_address',
    method: 'get',
    params: parameter
  })
}

export function selectAddressDepart (parameter) {
  return request({
    url: '/admin/depart/select_addressDepart',
    method: 'get',
    params: parameter
  })
}

export function addThirdCompany (data) {
  return request({
    url: '/web/ThirdCompany/add_ThirdCompany',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data
  })
}

export function updateThirdCompany (data) {
  return request({
    url: '/web/ThirdCompany/update_ThirdCompany',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data
  })
}

export function delThirdCompany (id) {
  return request({
    url: '/web/ThirdCompany/del_ThirdCompany',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: {
      id,
      isDelete: -1
    }
  })
}

export function downloadExecl (url) {
  return request({
    url,
    method: 'get',
    responseType: 'blob'
  })
}

// export function getThirdCompany (data) {
//   return request({
//     url: '/web/ThirdCompany/get_ThirdCompany',
//     method: 'post',
//     headers: {
//       'Content-Type': 'application/json;charset=UTF-8'
//     },
//     data
//   })
// }
// 

// 分页查询403网站链接
export function getWebLinksPageLists (parameter) {
  return request({
    url: '/admin/link/get_webLinksPageLists',
    method: 'get',
    params: parameter
  })
}


// 创建403
export function addWebLink (data) {
  return request({
    url: '/admin/link/add_webLink',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data
  })
}

// 修改403
export function updateWebLink (data) {
  return request({
    url: '/admin/link/update_webLink',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data
  })
}

// 删除403
export function deleteWebLink (id) {
  return request({
    url: '/admin/link/delete_webLink',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: {
      id,
      isDelete: -1
    }
  })
}